using System;
using System.Collections.Generic;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
using AUSRIS.Reports.Utilities.Deployment;

namespace AUSRIS.Reports.Utilities.Deployment.Console
{
	class Program
	{
		static void Main(string[] args)
		{
			try
			{
				//todo: use a command line switch to turn off prompt and supply deploymentSetName;
				bool prompt = true;
				string deploymentSetName = null;

				System.Console.ForegroundColor = ConsoleColor.DarkCyan;
				System.Console.WriteLine(new string('*', 40));
				System.Console.WriteLine("AUSRIS Report Deployment Utility");
				System.Console.WriteLine("Copyright (C) HQ Air University 2008");
				System.Console.WriteLine(new string('*', 40));
				System.Console.ResetColor();
				System.Console.WriteLine();
				System.Console.WriteLine("Reading application configuration...");

				IApplicationContext context = ContextRegistry.GetContext();

				IPublisher publisher = (IPublisher) context.GetObject("IPublisher");

				System.Console.WriteLine("Using {0}", publisher.GetType().Name);
				System.Console.WriteLine();
				System.Console.WriteLine();

				if ( string.IsNullOrEmpty(deploymentSetName) )
				{
					System.Console.Write("Enter Deployment Set Name: ");
					deploymentSetName = System.Console.ReadLine();
				}

				if ( !string.IsNullOrEmpty(deploymentSetName) )
				{

					publisher.LoadDeploymentSet(deploymentSetName);
					System.Console.WriteLine("Deployment Set {0} Loaded.", deploymentSetName);
					if ( prompt )
					{
						System.Console.WriteLine();
						System.Console.Write("Proceed with deployment? (Y/N): ");
						if ( System.Console.ReadKey().Key == ConsoleKey.Y )
						{
							System.Console.WriteLine();
							publisher.Publish();
						}
					}

				}
			}
			catch ( Exception ex )
			{
				System.Console.ForegroundColor = ConsoleColor.Red;
				System.Console.WriteLine(ex.ToString());
				System.Console.ResetColor();
			}
			System.Console.ReadLine();
		}
	}
}